home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / cpp-olib.zip / DEMOS.ZIP / GUIDEMO.CPP < prev    next >
C/C++ Source or Header  |  1992-12-28  |  16KB  |  648 lines

  1. //**************************************************************************
  2. //    This is a demo program to show how to use some of the features of
  3. //    the GUI libraries of the ObjectEase package. To compile and run this
  4. //    demo create a project file including the files GUI.LIB and GUIDEMO.CPP.
  5. //    Make sure that the files are located where the project says they are.
  6. //    You may also need to change to path to the GUI.H file in the #includes
  7. //    portion of this file.
  8. //
  9. //    Also note that the following files MUST be in the same directory as
  10. //    The executable for this program to operate properly:
  11. //
  12. //        B1.BTN
  13. //        B2.BTN
  14. //        I1.ICN
  15. //        I2.ICN
  16. //        I3.ICN
  17. //
  18. //    BE SURE YOU ARE COMPILING FOR THE LARGE MEMORY MODEL!!!
  19. //**************************************************************************
  20.  
  21. #include "gui.h"
  22. #include <conio.h>
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <graphics.h>
  26.  
  27. #define BKG     3
  28.  
  29. //*************************  FUNCTION PROTOTYPES  **************************
  30.  
  31. void initgraphicdemo();
  32. void gbuttondemo();
  33. void graphbuttondemo();
  34. void paneldemo();
  35. void icondemo();
  36. void acticondemo();
  37. void gmenudemo();
  38. void inputdemo();
  39. void mcursordemo();
  40.  
  41. void write3d(int,char *);
  42. void early_exit();
  43. void norm_exit();
  44. void do_siren();
  45. void do_tele();
  46.  
  47. //***************************  GLOBAL VARIABLES  ***************************
  48.  
  49. extern Mcursor the_mouse;
  50. Screen screen;
  51. int mouse_present=0;
  52. char ch;
  53.  
  54. //**************************************************************************
  55. //              MAIN
  56.  //**************************************************************************
  57.  
  58. void main()
  59. {
  60.     initgraphicdemo();
  61.     closegraph();
  62.     puts("Thank you for previewing the ObjectEase library from");
  63.     puts("David S. Reinhart Associates");
  64.     exit(0);
  65. }
  66.  
  67. //**************************************************************************
  68. //**************************************************************************
  69. //**************************************************************************
  70.  
  71. void initgraphicdemo()
  72. {
  73.     screen.VGA_480_16();
  74.     delay(1000);
  75.  
  76.     if(!the_mouse.init()) {
  77.         puts("Unable to detect mouse driver. Graphic portion of this demo");
  78.         puts("requires a mouse.");
  79.         closegraph();
  80.         exit(1);
  81.         }
  82.  
  83.     setfillstyle(SOLID_FILL,BKG);
  84.     bar(0,0,getmaxx(),getmaxy());
  85.  
  86.     Bevel mainpanel;
  87.  
  88.     mainpanel.init(50,75,540,125,THICK);
  89.     mainpanel.show();
  90.  
  91.     settextjustify(CENTER_TEXT,TOP_TEXT);
  92.     write3d(100,"ObjectEase graphics demonstration for Borland C++ and");
  93.     write3d(115,"Turbo C++. This demo and the included graphics library file(s)");
  94.     write3d(130,"(c) Copyright 1992, David S. Reinhart Associates");
  95.  
  96.     write3d(160,"Press the <ENTER> key or the right mouse key to progress through");
  97.     write3d(175,"the demo.");
  98.  
  99.     Panel copyrightpanel;
  100.     copyrightpanel.init(3,455,634,21,OUT,THIN);
  101.     copyrightpanel.show();
  102.     setcolor(0);
  103.     write3d(465,"(c) Copyright 1992 - David S. Reinhart Associates");
  104.  
  105.     the_mouse.arm();
  106.  
  107.     int selected=0;
  108.     while(!selected) {
  109.         while(!kbhit() && !the_mouse.RBP());
  110.         if(kbhit()) {
  111.             if((ch=getch())==27)
  112.                 early_exit();
  113.             while(kbhit())getch();
  114.             selected=1;
  115.             }
  116.         if(the_mouse.RBP())
  117.             selected=1;
  118.         }
  119.  
  120.     gbuttondemo();
  121.     graphbuttondemo();
  122.     icondemo();
  123.     acticondemo();
  124.     paneldemo();
  125.     gmenudemo();
  126.     inputdemo();
  127.     mcursordemo();
  128. }
  129.  
  130. //**************************************************************************
  131.  
  132. void mcursordemo()
  133. {
  134.     int cur=1;
  135.  
  136.     the_mouse.hide();
  137.     setfillstyle(SOLID_FILL,3);
  138.     bar(0,0,getmaxx(),getmaxy()-30);
  139.  
  140.     write3d(20,"Press the left mouse key to cycle through cursors.");
  141.     write3d(35,"Press right mouse key to end.");
  142.  
  143.     the_mouse.show();
  144.     while(!the_mouse.RBP()) {
  145.         if(the_mouse.LBP()) {
  146.             cur++;
  147.             if(cur>16)cur=1;
  148.             the_mouse.changeto(cur);
  149.             while(the_mouse.LBP());
  150.             }
  151.         }
  152. }
  153.  
  154. //**************************************************************************
  155.  
  156. void gbuttondemo()
  157. {
  158.     setfillstyle(SOLID_FILL,BKG);
  159.     the_mouse.hide();
  160.     bar(0,0,getmaxx(),getmaxy()-40);
  161.  
  162.     Bevel mainpanel;
  163.     mainpanel.init(30,70,580,230,THICK);
  164.     mainpanel.show();
  165.  
  166.     write3d(85,"Buttons are one of the most fundamental graphic objects.");
  167.     write3d(100,"They are very popular within graphics environments");
  168.     write3d(115,"for getting user input. You, the programmer, have complete");
  169.     write3d(130,"control over how these button objects function. That is");
  170.     write3d(145,"to say, whether the resulting action takes place when the");
  171.     write3d(160,"button is pressed or released; how long the button remains");
  172.     write3d(175,"depressed; etc...  Experiment with the buttons below.");
  173.  
  174.     Button lowbutton;
  175.     Button medbutton;
  176.     Button hibutton;
  177.     Panel buttonpanel;
  178.  
  179.     lowbutton.init(150,230," LOW ",TEXT);
  180.     medbutton.init(300,230," MED ",TEXT);
  181.     hibutton.init(450,230," HI  ",TEXT);
  182.     buttonpanel.init(130,220,390,45,IN,THICK);
  183.     buttonpanel.show();
  184.  
  185.     lowbutton.show();
  186.     medbutton.show();
  187.     hibutton.show();
  188.  
  189.     the_mouse.show();
  190.     int selected=0;
  191.  
  192.     flushkeys();
  193.     while(!selected) {
  194.         if(the_mouse.LBP()) {
  195.             if(lowbutton.hit()) {
  196.                 lowbutton.press();
  197.                 while(the_mouse.LBP() && lowbutton.hit());
  198.                 lowbutton.show();
  199.                 if(lowbutton.hit()) {
  200.                     sound(220);
  201.                     delay(500);
  202.                     nosound();
  203.                     continue;
  204.                     }
  205.                 }
  206.             if(medbutton.hit()) {
  207.                 medbutton.press();
  208.                 while(the_mouse.LBP() && medbutton.hit());
  209.                 medbutton.show();
  210.                 if(medbutton.hit()) {
  211.                     sound(440);
  212.                     delay(500);
  213.                     nosound();
  214.                     continue;
  215.                     }
  216.                 }
  217.             if(hibutton.hit()) {
  218.                 hibutton.press();
  219.                 while(the_mouse.LBP() && hibutton.hit());
  220.                 hibutton.show();
  221.                 if(hibutton.hit()) {
  222.                     sound(880);
  223.                     delay(500);
  224.                     nosound();
  225.                     continue;
  226.                     }
  227.                 }
  228.             }// end if the_mouse.LBP
  229.         if(the_mouse.RBP()) {
  230.             selected=1;
  231.             }
  232.         if(kbhit()) {
  233.             if((ch=getch())==27)
  234.                 early_exit();
  235.             while(kbhit())getch();
  236.             selected=1;
  237.             }
  238.         }// end while !selected
  239. }
  240.  
  241. //**************************************************************************
  242.  
  243. void graphbuttondemo()
  244. {
  245.     the_mouse.hide();
  246.     setfillstyle(SOLID_FILL,BKG);
  247.     bar(0,0,getmaxx(),getmaxy()-40);
  248.  
  249.     Bevel mainpanel;
  250.     mainpanel.init(50,50,getmaxx()-100,250,THICK);
  251.     mainpanel.show();
  252.  
  253.     write3d(75,"Buttons can have not only text labels, but graphics as well!");
  254.     write3d(90,"Graphics not only make the interface look nicer, but can");
  255.     write3d(105,"also make the button's function more intuitive for the end user.");
  256.     write3d(120,"Try to guess what the outcome will be before trying out each of");
  257.     write3d(135,"the buttons below.");
  258.     write3d(165,"By the way, these graphic buttons are easy to create using the");
  259.     write3d(180,"ICONEDIT program supplied in this package.");
  260.  
  261.     Panel buttonpanel;
  262.     Button sirenbutton;
  263.     Button telebutton;
  264.  
  265.     buttonpanel.init(270,220,100,50,IN,THICK);
  266.     buttonpanel.show();
  267.     sirenbutton.init(285,235,"b1",1);
  268.     telebutton.init(330,235,"b2",1);
  269.     sirenbutton.show();
  270.     telebutton.show();
  271.     the_mouse.show();
  272.  
  273.     flushkeys();
  274.     int selected=0;
  275.     while(!selected) {
  276.         if(the_mouse.RBP())
  277.             selected=1;
  278.         if(kbhit()) {
  279.             if((ch=getch())==27)
  280.                 early_exit();
  281.             while(kbhit())getch();
  282.             selected=1;
  283.             }
  284.         if(the_mouse.LBP()) {
  285.             if(sirenbutton.hit()) {
  286.                 sirenbutton.press();
  287.                 while(the_mouse.LBP() && sirenbutton.hit());
  288.                 sirenbutton.show();
  289.                 if(sirenbutton.hit()) {
  290.                     do_siren();
  291.                     continue;
  292.                     }
  293.                 }
  294.             if(telebutton.hit()) {
  295.                 telebutton.press();
  296.                 while(the_mouse.LBP() && telebutton.hit());
  297.                 telebutton.show();
  298.                 if(telebutton.hit()) {
  299.                     do_tele();
  300.                     continue;
  301.                     }
  302.                 }
  303.             }
  304.         }
  305. }
  306.  
  307. //**************************************************************************
  308.  
  309. void paneldemo()
  310. {
  311.     the_mouse.hide();
  312.     setfillstyle(SOLID_FILL,BKG);
  313.     bar(0,0,getmaxx(),getmaxy()-40);
  314.  
  315.     Bevel mainpanel;
  316.     mainpanel.init(10,10,getmaxx()-20,70,THICK);
  317.     mainpanel.show();
  318.  
  319.     write3d(25,"Panels offer an attractive way to partition the graphics screen.");
  320.     write3d(40,"Here are some of the different types of panels that can easily");
  321.     write3d(55,"be implemented using the ObjectEase library.");
  322.  
  323.     Panel inthick;
  324.     Panel inthin;
  325.     Panel outthick;
  326.     Panel outthin;
  327.     Bevel thin;
  328.     Bevel thick;
  329.  
  330.     delay(2000);
  331.     write3d(90,"THICK STYLES                               THIN STYLES");
  332.     inthick.init(50,105,200,100,IN,THICK);
  333.     inthick.show();
  334.     inthin.init(390,105,200,100,IN,THIN);
  335.     inthin.show();
  336.     delay(1000);
  337.     outthick.init(50,220,200,100,OUT,THICK);
  338.     outthick.show();
  339.     outthin.init(390,220,200,100,OUT,THIN);
  340.     outthin.show();
  341.     delay(1000);
  342.     thick.init(50,335,200,100,THICK);
  343.     thick.show();
  344.     thin.init(390,335,200,100,THIN);
  345.     thin.show();
  346.  
  347.     the_mouse.show();
  348.     flushkeys();
  349.     while(!kbhit() && !the_mouse.RBP());
  350.     if(kbhit()) {
  351.         if((ch=getch())==27)
  352.             early_exit();
  353.         while(kbhit())getch();
  354.         }
  355. }
  356.  
  357. //**************************************************************************
  358.  
  359. void icondemo()
  360. {
  361.     the_mouse.hide();
  362.     setfillstyle(SOLID_FILL,BKG);
  363.     bar(0,0,getmaxx(),getmaxy()-40);
  364.  
  365.     Bevel mainpanel;
  366.     mainpanel.init(50,50,getmaxx()-100,200,THICK);
  367.     mainpanel.show();
  368.  
  369.     write3d(75,"What paint program would be complete without icons? Icons are");
  370.     write3d(90,"as intuitive to use as buttons, and once again, using the");
  371.     write3d(105,"ICONEDIT program, they are easy for you, the programmer, to");
  372.     write3d(120,"create. Check out the action of the icons below...");
  373.  
  374.     Panel iconpanel;
  375.     Icon drawicon;
  376.     Icon painticon;
  377.  
  378.     iconpanel.init(250,160,getmaxx()-500,50,IN,THICK);
  379.     iconpanel.show();
  380.     drawicon.init(280,170,"i1");
  381.     painticon.init(330,170,"i2");
  382.     drawicon.show();
  383.     painticon.show();
  384.     the_mouse.show();
  385.  
  386.     flushkeys();
  387.     int selected=0;
  388.     while(!selected) {
  389.         if(the_mouse.RBP())
  390.             selected=1;
  391.         if(kbhit()) {
  392.             if((ch=getch())==27)
  393.                 early_exit();
  394.             while(kbhit())getch();
  395.             selected=1;
  396.             }
  397.         if(the_mouse.LBP()) {
  398.             if(painticon.hit()) {
  399.                 if(!painticon.ispressed()) {
  400.                     painticon.choose();
  401.                     drawicon.show();
  402.                     while(the_mouse.LBP());
  403.                     continue;
  404.                     }
  405.                 }
  406.             if(drawicon.hit()) {
  407.                 if(!drawicon.ispressed()) {
  408.                     drawicon.choose();
  409.                     painticon.show();
  410.                     while(the_mouse.LBP());
  411.                     continue;
  412.                     }
  413.                 }
  414.             }
  415.         }
  416. }
  417.  
  418. //**************************************************************************
  419.  
  420. void acticondemo()
  421. {
  422.     the_mouse.hide();
  423.     setfillstyle(SOLID_FILL,BKG);
  424.     bar(0,0,getmaxx(),getmaxy()-40);
  425.  
  426.     Bevel mainpanel;
  427.     mainpanel.init(50,50,getmaxx()-100,300,THICK);
  428.     mainpanel.show();
  429.  
  430.     write3d(75,"Here's a neat graphic feature that you don't see everyday.");
  431.     write3d(90,"Want to really jazz up your interface? Want to make it stand");
  432.     write3d(105,"out in a crowd?! Instead of reversing the image of your icons");
  433.     write3d(120,"when they are selected, make them come to life! Click the icon");
  434.     write3d(135,"below to see what I mean.");
  435.     write3d(165,"And guess what... Right! These icons are also easy to create");
  436.     write3d(180,"using the ICONEDIT program");
  437.  
  438.     Panel iconpanel;
  439.     iconpanel.init(270,230,getmaxx()-(270*2),70,IN,THICK);
  440.     iconpanel.show();
  441.     Acticon aicon;
  442.     aicon.init(305,250,"i3");
  443.     aicon.show(1);
  444.     the_mouse.show();
  445.  
  446.     int selected=0;
  447.     while(!selected) {
  448.         if(the_mouse.RBP())
  449.             selected=1;
  450.         if(kbhit()) {
  451.             if((ch=getch())==27)
  452.                 early_exit();
  453.             while(kbhit())getch();
  454.             selected=1;
  455.             }
  456.         if(the_mouse.LBP()) {
  457.             if(aicon.hit()) {
  458.                 while(!the_mouse.RBP() && !kbhit())
  459.                     aicon.backforth(2);
  460.                 if(kbhit()) {
  461.                     flushkeys();
  462.                     selected=1;
  463.                     }
  464.                 if(the_mouse.RBP())
  465.                     selected=1;
  466.                 }
  467.             }
  468.         }
  469. }
  470.  
  471. //**************************************************************************
  472.  
  473. void gmenudemo()
  474. {
  475.     the_mouse.hide();
  476.     setfillstyle(SOLID_FILL,BKG);
  477.     bar(0,0,getmaxx(),getmaxy()-40);
  478.  
  479.     Bevel mainpanel;
  480.     mainpanel.init(30,50,getmaxx()-60,130,THICK);
  481.     mainpanel.show();
  482.  
  483.     write3d(75,"Do you need to include point and shoot type menu bars in your");
  484.     write3d(90,"applications? No problem! Using the ObjectEase library makes it a snap");
  485.     write3d(105,"for you to include graphic pulldown menus! See for yourself below.");
  486.     write3d(120,"You may want to note that the way these menus are implemented");
  487.     write3d(135,"requires you to keep the left mouse key pressed until you have made");
  488.     write3d(150,"your selection.");
  489.  
  490.     setfillstyle(SOLID_FILL,15);
  491.     bar(0,200,getmaxx(),210);
  492.     setfillstyle(SOLID_FILL,1);
  493.     bar(0,211,getmaxx(),350);
  494.  
  495.     Gmenubutton menubutton1;
  496.     Gmenubutton menubutton2;
  497.     gitemarray  itemarray1;
  498.     gitemarray  itemarray2;
  499.     Gmenu       gmenu1;
  500.     Gmenu       gmenu2;
  501.  
  502.     strcpy(itemarray1[1],"Item 1");
  503.     strcpy(itemarray1[2],"Item 2");
  504.     strcpy(itemarray1[3],"Item 3");
  505.     strcpy(itemarray1[4],"Item 4");
  506.  
  507.     strcpy(itemarray2[1],"Item 1");
  508.     strcpy(itemarray2[2],"Item 2");
  509.     strcpy(itemarray2[3],"Item 3");
  510.     strcpy(itemarray2[4],"Item 4");
  511.  
  512.     gmenu1.init(0,211,4,itemarray1);
  513.     gmenu2.init(100,211,4,itemarray2);
  514.  
  515.     menubutton1.init(0,200,0,15,15,0,"Menu 1");
  516.     menubutton2.init(100,200,0,15,15,0,"Menu 2");
  517.     menubutton1.show();
  518.     menubutton2.show();
  519.     the_mouse.show();
  520.  
  521.     int selected=0;
  522.     while(!selected) {
  523.         if(kbhit()) {
  524.             if((ch=getch())==27)
  525.                 early_exit();
  526.             flushkeys();
  527.             selected=1;
  528.             }
  529.         if(the_mouse.RBP())
  530.             selected=1;
  531.         if(the_mouse.LBP()) {
  532.             if(menubutton1.hit()) {
  533.                 menubutton1.press();
  534.                 gmenu1.show();
  535.                 gmenu1.hide();
  536.                 menubutton1.show();
  537.                 }
  538.             if(menubutton2.hit()) {
  539.                 menubutton2.press();
  540.                 gmenu2.show();
  541.                 gmenu2.hide();
  542.                 menubutton2.show();
  543.                 }
  544.             }
  545.         }
  546. }
  547.  
  548. //**************************************************************************
  549.  
  550. void inputdemo()
  551. {
  552.     the_mouse.hide();
  553.     setfillstyle(SOLID_FILL,BKG);
  554.     bar(0,0,getmaxx(),getmaxy()-40);
  555.  
  556.     Bevel mainpanel;
  557.     mainpanel.init(30,50,getmaxx()-60,150,THICK);
  558.     mainpanel.show();
  559.  
  560.     write3d(75,"Getting text input from a graphic based application used to be");
  561.     write3d(90,"a real hassle... NO MORE! The ObjectEase includes functions for");
  562.     write3d(105,"laying out text input fields, simulating the text cursor, and");
  563.     write3d(120,"handling the text strings input by the user. Now you can");
  564.     write3d(135,"capture graphic text input as easily as in text mode.");
  565.     write3d(150,"Try out the sample dialog below.");
  566.  
  567.     Panel dialogpanel;
  568.     dialogpanel.init(150,250,getmaxx()-300,85,IN,THICK);
  569.     dialogpanel.show();
  570.  
  571.     setcolor(15);
  572.     settextjustify(LEFT_TEXT,TOP_TEXT);
  573.     gprintxy(170,275,"First Name: ");
  574.     gprintxy(170,305,"Last Name:  ");
  575.  
  576.     Gstring fname;
  577.     Gstring lname;
  578.     fname.init(270,279,20,0);
  579.     lname.init(270,309,20,0);
  580.     fname.show();
  581.     lname.show();
  582.  
  583.     fname.get_input();
  584.     lname.get_input();
  585.  
  586.     write3d(400,"Press <ENTER> to continue...");
  587.  
  588.     flushkeys();
  589.     while(!the_mouse.RBP() && !kbhit());
  590.     if(kbhit()) {
  591.         if((ch=getch())==27)
  592.             early_exit();
  593.         flushkeys();
  594.         }
  595. }
  596.  
  597. //**************************************************************************
  598.  
  599. void write3d(int y,char *text)
  600. {
  601.     settextjustify(CENTER_TEXT,TOP_TEXT);
  602.     setcolor(0);
  603.     outtextxy(getmaxx()/2,y,text);
  604.     setcolor(15);
  605.     outtextxy((getmaxx()/2)-1,y-1,text);
  606. }
  607.  
  608. //**************************************************************************
  609.  
  610. void do_siren()
  611. {
  612.     int i;
  613.  
  614.     for(i=500;i<1000;i+=7) {
  615.         sound(i);
  616.         delay(12);
  617.         }
  618.     for(i=1000;i>500;i-=7) {
  619.         sound(i);
  620.         delay(12);
  621.         }
  622.     nosound();
  623. }
  624.  
  625. //**************************************************************************
  626.  
  627. void do_tele()
  628. {
  629.     int i;
  630.  
  631.     for(i=0;i<14;i++) {
  632.         sound(440);
  633.         delay(30);
  634.         sound(880);
  635.         delay(30);
  636.         }
  637.     nosound();
  638. }
  639.  
  640. //**************************************************************************
  641.  
  642. void early_exit()
  643. {
  644.     closegraph();
  645.     puts("You have not seen the entire demonstration.");
  646.     exit(0);
  647. }
  648.